﻿import mx.utils.Delegate;
class cn.eminia.AS2.LB {
	function LB(obj) {
		/*if (mc == undefined || mc.constructor != MovieClip) {
		throw ('!! 错误，未知定加载容器');
		}*/
		var dd = _root.getNextHighestDepth();
		var lbdd = _root.createEmptyMovieClip('lb', dd);
		lbdd.onEnterFrame = Delegate.create(this, function () {
			var tt = _root.getBytesTotal();
			var ld = _root.getBytesLoaded();
			obj.onEF({per:Math.round(ld/tt*100), tt:tt, ld:ld});
			if (tt == ld) {
				var onOK = Delegate.create(obj.scope, obj.onOK);
				onOK();
				delete lbdd.onEnterFrame;
				removeMovieClip(lbdd);
			}
		});
	}
	static function LoR(scope, obj) {
		with (scope) {
			bar._x = msk._x-msk._width;
			bar.onEnterFrame = function() {
				this._x += (this.tx-this._x)*.3;
			};
		}
		new cn.eminia.AS2.LB({scope:scope, onOK:obj.onOK, onEF:Delegate.create(scope, function (evt) {
			var tf = this.tf;
			var msk = this.msk;
			var bar = this.bar;
			tf.text = (evt.per+"%");
			bar.tx = (msk._x-bar._width)+msk._width*evt.per/100;
		})});
	}
	static function LoC(scope, obj) {
		with (scope) {
			bar._x = msk._x-msk._width;
			bar.onEnterFrame = function() {
				this._x += (this.tx-this._x)*.3;
			};
		}
		var ld = new cn.eminia.AS2.Ld(obj.ctt, {stt:function (evt) {
			trace('stt');
		}, pro:function (evt) {
			trace('pro'+evt.per);
			var tf = scope.tf;
			var msk = scope.msk;
			var bar = scope.bar;
			tf.text = (evt.per+"%");
			bar.tx = (msk._x-bar._width)+msk._width*evt.per/100;
		}, ok:function (evt) {
			trace('dmc -> '+evt.mc);
			obj.onOK(evt);
		}, scope:scope});
		ld.load(obj.url);
		//
	}
	static function chk(scope, id) {
		if (scope.constructor != MovieClip) {
			throw new Error('!! 错，该函数用代理 -> '+id);
		}
	}
}
